/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clienteped;

import Swing.MainFrame;
import clienteped.NetworkManagerOld.NetworkReader;
import clienteped.NetworkManagerOld.NetworkSender;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;

/**
 *
 * @author Micosil
 */
public class ClientePED {
    
    public static boolean remainConnected = true;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args){
        
        
        
        MainFrame mainFrame = new MainFrame();
        mainFrame.setVisible(true);        
        try{
        Socket socket;
        BufferedReader configReader = new BufferedReader(new FileReader(new File("Config.txt")));
        socket = new  Socket(configReader.readLine(), 9000);
        NetworkReader nin = new NetworkReader(socket);
        mainFrame.setReader(nin);
        NetworkSender nout = new NetworkSender(socket);        
        mainFrame.setWriter(nout);
        configReader.close();
        while(remainConnected){
            while(nin.thereAreThingsToRead())
            mainFrame.updateText();
            if (nout.thereIsStuffToSend())
                nout.sendAll();
            Thread.sleep(50);
        }                                    
        }catch (IOException | InterruptedException ex){
            ex.printStackTrace();
        }
    }
    
    
}
